﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Globalization;
using ShredTheLog.Api;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition;

namespace ShredTheLog.Controls
{
    public sealed class NonEmptyStringValidationRule : ValidationRule
    {
        public NonEmptyStringValidationRule()
        {
            Globals.CompositionContainer.SatisfyImportsOnce(this);
        }

        [Import]
        private IShredServices ShredServices { get; set; }

        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            var v = value as string;
            if (!String.IsNullOrEmpty(v))
                return new ValidationResult(true, null);
            else
                return new ValidationResult(false, ShredServices.GetLocalizedString("s_ExpectingNonEmptyString"));
        }
    }
}
